/**
 * @Project : algorithm-learning
 * @Author : Ruoyu Wang
 * @User : Momenta
 * @DateTime : 2024/4/14 18:48
 */

#include <iostream>
#include <vector>

using namespace std;


struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;

    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution {
public:
    bool dfs(TreeNode *node, int sum, int target) {
        if (node == nullptr)return false;
        int s = node->val + sum;
        if (node->left == nullptr && node->right == nullptr) {
            return s == target;
        }
        return dfs(node->left, s, target) && dfs(node->right, s, target);
    }

    bool hasPathSum(TreeNode *root, int sum) {
        return dfs(root, 0, sum);
    }
};

int main() {
    Solution sl;
    return 0;
}